/**
* -------------------------------------------------------------
* @author  cl
* @date: 2021-12-28 17:28:05
* @description: 上传文件bind表 controller
* -------------------------------------------------------------
* @version 1.0.0
* @Copyright (c) 中科星图-版权所有
*/
package com.geovis.boot.service.demo.file.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.geovis.boot.common.dto.Result;
import com.geovis.boot.common.util.RedisUtils;
import com.geovis.boot.common.util.ResultUtil;
import com.geovis.boot.service.demo.file.entity.FileBind;
import com.geovis.boot.service.demo.file.service.IFileBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RestController
@Api(description = "上传文件bind表管理接口")
@RequestMapping("/fileBind")
public class FileBindController {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private IFileBindService iFileBindService;

    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<FileBind> get(@RequestParam String id){
        FileBind fileBind = iFileBindService.getById(id);
        return new ResultUtil<FileBind>().setData(fileBind);
    }

    //sql语句查询方式
    @RequestMapping(value = "/getFileBindById", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<FileBind> getFileBindById(@RequestParam String id){

        FileBind fileBind = iFileBindService.selectFileBinds(id);
        return new ResultUtil<FileBind>().setData(fileBind);
    }

    @RequestMapping(value = "/getByParam", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询获取")
    public Result<IPage> getByParam(@RequestParam Long pageNum,
                                       @RequestParam Long pageSize,
                                       @RequestParam(required = false) String uri,
                                       @RequestParam(required = false) String path){
        IPage byParam = iFileBindService.getByParam(pageNum, pageSize, uri, path);
        return new ResultUtil<IPage>().setData(byParam);
    }

    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "获取全部数据")
    public Result<List<FileBind>> getAll(@RequestParam(required = false) String updateBy){

        List<FileBind> list = iFileBindService.getList(updateBy);
        return new ResultUtil<List<FileBind>>().setData(list);
    }

    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑或更新数据")
    public Result<FileBind> saveOrUpdate(@RequestBody FileBind fileBind){

        if(iFileBindService.saveOrUpdate(fileBind)){
            return new ResultUtil<FileBind>().setData(fileBind);
        }
        return new ResultUtil<FileBind>().setErrorMsg("操作失败");
    }

    @RequestMapping(value = "/delById", method = RequestMethod.DELETE)
    @ApiOperation(value = "通过id删除")
    public Result<Object> delById(@RequestParam String id){

        if(iFileBindService.removeById(id)){
            return new ResultUtil<Object>().setSuccessMsg("通过id删除数据成功");
        }else{
            return new ResultUtil<Object>().setErrorMsg("通过id删除数据失败");
        }
    }

    @RequestMapping(value = "/delByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@RequestParam String[] ids){

        if(iFileBindService.batchRemoveByIds(ids)){
            return new ResultUtil<Object>().setSuccessMsg("通过id删除数据成功");
        }else{
            return new ResultUtil<Object>().setErrorMsg("通过id删除数据失败");
        }
    }

}
